<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .box {
      position: relative;
      width: 400px;
      height: 400px;
      background-color: #eee;
      margin: 100px auto;
    }
    .son {
      position: absolute;
      /* 水平居中 */
      left: 50%;
      margin-left: -100px;
      /* 垂直居中 */
      top: 50%;
      margin-top: -100px;
      width: 200px;
      height: 200px;
      background-color: #cfa;
    }
  </style>
  <body>
    <div class="box">
      <div class="son"></div>
    </div>
  </body>
</html>
